home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: New Zealand Amiga Users Group / New Zealand Amiga Users Group Newsdisk v25 (1989-08)(NZAmigaUG).zip / New Zealand Amiga Users Group Newsdisk v25 (1989-08)(NZAmigaUG).adf / StrucBrowser / sb.src.zoo / SB.c < prev    next >
C/C++ Source or Header  |  1988-06-22  |  8KB  |  282 lines

  1. /*    The Transactor Structure Browser (SB) V1.0
  2.  *    From Transactor Magazine, Volume 7, Issue 6
  3.  *
  4.  *    By Nick Sullivan and Chris Zamara (AHA!) (c) 1986
  5.  *
  6.  *      Additions by David Annett 16 July 1989
  7.  *
  8.  *    SB displays system structures via pointers found
  9.  *    in other structures. You start from IntuitionBase.
  10.  *
  11.  *    For structures implemented see SB.readme
  12.  *
  13.  *    Usage is through Intuition, clicking on a structure member
  14.  *    names to display info or a new structure.
  15.  *
  16.  *    *****  THIS PROGRAM MAY BE FREELY DISTRIBUTED  *****
  17.  */
  18.  
  19. /* include not needed for Aztec C using provided makefile */
  20.  
  21. /* I keep all the files in directory sb on df1:
  22.  * To keep the system happy, I 'ASSIGN SB: DF1:SB' then 'CD SB:'. GG.
  23.  */ 
  24.  
  25.  
  26. #include "sb.h"
  27. #define MIN(x,y) ((x)<(y)?(x):(y))
  28. #define FLAGFIELDS 4
  29. extern struct IntuitionBase *IntuitionBase;
  30. extern struct GfxBase *GfxBase;
  31. extern struct ExecBase *ExecBase;
  32. extern struct ExpansionBase *ExpansionBase;
  33. /*extern struct RomBootBase *RomBootBase;*/
  34. extern struct IntuiText ChoiceText[], BackIText;
  35. APTR OpenLibrary ();
  36. int level = 0; /* current level of nesting */
  37. static char textlines[MAXGADG + 1][80];
  38. extern void PrIntuiBase(), HexLine();
  39.  
  40. void main()
  41. {
  42. int choice = -1;
  43.   SetupGadg();
  44.   OpenStuff(); /* open intuition library & window */
  45.   while (choice) {
  46.     putHeader("Choose a library structure", NULL);
  47.     ChoiceText[0].IText = (UBYTE *)" Intuition       struct Library";
  48.     ChoiceText[1].IText = (UBYTE *)" Graphics        struct Library";
  49.     ChoiceText[2].IText = (UBYTE *)" Exec            struct Library";
  50.     ChoiceText[3].IText = (UBYTE *)" Expansion       struct Library";
  51. /*    ChoiceText[4].IText = (UBYTE *)" RomBoot         struct Library";*/
  52.     BackIText.IText = (UBYTE *)"  Quit  Program";
  53.     switch (choice = GetChoice(4)) {
  54.       case 1:
  55.         PrIntuiBase ("The IntuitionBase structure", IntuitionBase);
  56.         break;
  57.       case 2:
  58.         PrGfxBase ("The GfxBase structure", GfxBase);
  59.         break;
  60.       case 3:
  61.         PrExecBase ("The ExecBase structure", ExecBase);
  62.         break;
  63.       case 4:
  64.         PrExpansionBase ("The ExpanionBase structure", ExpansionBase);
  65.         break;
  66. /*      case 5:
  67.         PrRomBootBase ("The RomBootBase structure", RomBootBase);
  68.         break;*/
  69.     }
  70.   }
  71.   CloseOut();
  72. }
  73.  
  74.  
  75. void PrIntuiBase (string, IBase) char *string; struct IntuitionBase *IBase;
  76. {
  77. static struct StructData structdata[] = {
  78.      { " LibNode",           "struct Library",  0, SZ(Library) },
  79.      { " ViewLord",          "struct View",     0, SZ(View)    },
  80.      { " ActiveWindow",      "struct Window *", 5, PTRSIZE     },
  81.      { " ActiveScreen",      "struct Screen *", 5, PTRSIZE     },
  82.      { " FirstScreen",       "struct Screen *", 5, PTRSIZE     },
  83.      { "-Flags",         "ULONG",           11, PTRSIZE     },
  84.      { "-MouseY",         "WORD",        2, INTSIZE     },
  85.      { "-MouseX",         "WORD",        2, INTSIZE     },
  86.      { "-Seconds",         "ULONG",           11, PTRSIZE     },
  87.      { "-Micros",         "ULONG",           11, PTRSIZE     }
  88.   };
  89. int sum, choice = -1;
  90.   level++;
  91.   while (choice) {
  92.     sum = SetOptionText(string, structdata, (APTR)IBase, DATASIZE, 0);
  93.     switch (choice = GetChoice(DATASIZE)) {
  94.       case 1:
  95.         PrLibrary("Intuition's Library", &IBase->LibNode);
  96.         break;
  97.       case 2:
  98.         PrView("Intuition's view", &IBase->ViewLord);
  99.         break;
  100.       case 3:
  101.         if (IBase->ActiveWindow)
  102.           PrWindow("The currently active window", IBase->ActiveWindow);
  103.         break;
  104.       case 4:
  105.         PrScreen("The currently active screen", IBase->ActiveScreen);
  106.         break;
  107.       case 5:
  108.         PrScreen("The first screen on Intuition's list", IBase->FirstScreen);
  109.         break;
  110.     }
  111.   }
  112.   level--;
  113. }
  114.  
  115.  
  116. void put (option, stuff, base, offset)
  117. int option; struct StructData *stuff; char *base; int offset;
  118. {
  119. register long lnum;
  120. register int  inum;
  121. char buf[40];
  122. int i;
  123.   sprintf(textlines[option], "%-16s%-24s", stuff->membername, stuff->membertype);
  124.   switch (stuff->printtype) {
  125.     case 0:            /* don't print anything */
  126.       buf[0] = '\0';
  127.       break;
  128.     case 1:            /* print a long */
  129.       lnum = *(long *)(base + offset);
  130.       sprintf(buf, "$%8lx  %0ld", lnum, lnum);
  131.       break;
  132.     case 2:            /* print an int */
  133.       inum = *(short *)(base + offset);
  134.       sprintf(buf, "$%8x  %10d", inum, inum);
  135.       break;
  136.     case 3:            /* print a byte */
  137.       inum = *(base + offset);
  138.       sprintf(buf, "$%8x  %10d", inum, inum);
  139.       break;
  140.     case 4:            /* print a string */
  141.       if (!(lnum = *(long *)(base + offset) ))
  142.         sprintf(buf, "NULL");
  143.       else {
  144.         for (i = 0; i < 30 && *((char *)lnum + i); i++)
  145.           buf[i + 1] = *((char *)lnum + i);
  146.         buf[0] = buf[i + 1] = '\"';
  147.         buf[i + 2] = '\0';
  148.         if (*((char *)lnum + i))
  149.           strcat(buf, "...");
  150.       }
  151.       break;
  152.     case 5:            /* print a pointer */
  153.       if (!(lnum = *(long *)(base + offset) ))
  154.         sprintf(buf, "NULL");
  155.       else
  156.         sprintf(buf, "$%8lx  %10ld", lnum, lnum);
  157.       break;
  158.     case 11:            /* print a long */
  159.       lnum = *(long *)(base + offset);
  160.       sprintf(buf, "$%8lx  %10lu", lnum, lnum);
  161.       break;
  162.     case 12:            /* print an int */
  163.       inum = *(short *)(base + offset);
  164.       sprintf(buf, "$%8x  %10u", inum, inum);
  165.       break;
  166.     case 13:            /* print a byte */
  167.       inum = *(base + offset);
  168.       sprintf(buf, "$%8x  %10u", inum, inum);
  169.       break;
  170.   }
  171.   strcat(textlines[option], buf);
  172.   ChoiceText[option].IText = (UBYTE *)textlines[option];
  173. }
  174.  
  175.  
  176. void FlagPrint(string, names, flags)
  177. char *string, **names; ULONG flags;
  178. {
  179. int i, line, fields = FLAGFIELDS;
  180. char buf[32];
  181.   SetBackText(1); /* 'prev level' */
  182.   for (i = 0; i < 8; i++) {
  183.     strcpy(textlines[i], "-");
  184.     ChoiceText[i].IText = (UBYTE *)textlines[i];
  185.   }
  186.   putHeader(string, NULL);
  187.   for (i = line = 0; i < 32; i++) {
  188.     if ((flags & (1L << i)) && names[i]) {
  189.       sprintf(buf, "%-19s", names[i]);
  190.       strcat(textlines[line], buf);
  191.       if (!--fields) {
  192.         ChoiceText[line].IText = (UBYTE *)textlines[line];
  193.         line++;
  194.         fields = FLAGFIELDS;
  195.       }
  196.     }
  197.   }
  198.   if (fields < FLAGFIELDS)
  199.     ChoiceText[line].IText = (UBYTE *)textlines[line];
  200.   while (GetChoice(line + 1))
  201.     ;
  202. }
  203.  
  204.  
  205. void HexDump(string, address, unit, size)
  206. char *address, *string; int unit; long size;
  207. {
  208. int line = 0, c;
  209. char *buf[80];
  210.   BackIText.IText = (UBYTE *)" Exit Hex Dump  ";
  211.   if (size == -1)
  212.     size = 0x7ffff;
  213.   do {
  214.     sprintf(buf, "%s from %lx (%ld)", string, address, address);
  215.     putHeader(buf, NULL);
  216.     if (line == MAXGADG)
  217.       line = 0;
  218.     while (line < MAXGADG && size > 0) {
  219.       HexLine(address, unit, line++, size);
  220.       size -= 16;
  221.       address += 16;
  222.     }
  223.     c = GetChoice(size > 0 ? MAXGADG + 1 : line);
  224.   } while (size > 0 && c == MOREGADG);
  225. }
  226.  
  227.  
  228. void HexLine (address, unit, line, size)
  229. UBYTE *address; int unit, line; long size;
  230. {
  231. USHORT i, j;
  232. char buf[80];
  233. static char hexdigit[] = "0123456789ABCDEF";
  234.   sprintf(textlines[line], "-%6lx: ", address);
  235.   for (i = 0; i < MIN(size, 16); i += unit) {
  236.     switch (unit) {
  237.       case BYTESIZE:
  238.         j = *(address + i);
  239.         sprintf(buf, "%c%c ", hexdigit[j / 16], hexdigit[j % 16]);
  240.         break;
  241.       case INTSIZE:
  242.         sprintf(buf, "%04x ", *(short *)(address + i));
  243.         break;
  244.       case PTRSIZE:
  245.         sprintf(buf, "%08lx ", *(long *)(address + i));
  246.         break;
  247.     }
  248.     strcat(textlines[line], buf);
  249.   }
  250.   ChoiceText[line].IText = (UBYTE *)textlines[line];
  251. }
  252.  
  253.  
  254. int SetOptionText (hdrtext, data, object, size, offset)
  255. char *hdrtext;
  256. struct StructData *data;
  257. APTR object;
  258. int size, offset;
  259. {
  260. int i, sum;
  261.   SetBackText( offset ? 1 : 0);
  262.   putHeader(hdrtext, object);
  263.   for (i = sum = 0; i < size; i++) {
  264.     put(i, &data[i], object, sum + offset);
  265.     sum += data[i].datasize;
  266.   }
  267.   return (sum + offset);
  268. }
  269.     
  270.  
  271. void PrString(heading, string) char *heading, *string;
  272. {
  273. char *newstring, *malloc();
  274.   putHeader(heading, NULL);
  275.   newstring = malloc(strlen(string) + 1);
  276.   *newstring = '-';
  277.   strcpy(newstring + 1, string);
  278.   ChoiceText[0].IText = (UBYTE *)newstring;
  279.   GetChoice(1);
  280.   free(newstring);
  281. }
  282.